package com.control.qct.businesssteward.utils;

import android.content.Context;
import android.content.res.ColorStateList;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.TextAppearanceSpan;
import android.widget.TextView;

/**
 * 设置textview中部分文字的大小及颜色
 * Created by Administrator on 2017/12/18 0018.
 */

public class TextContentUtils {
    private static TextContentUtils mTextUtils;
    private Context mContext;

    public TextContentUtils(Context context) {
        this.mContext = context;
    }

    public static TextContentUtils getInstance(Context context) {
        if (mTextUtils == null) {
            mTextUtils = new TextContentUtils(context);
        }
        return mTextUtils;
    }

    /**
     * 设置金额字体大小
     *
     * @param tv
     * @param content
     */
    public void setTextSize(TextView tv, String content) {
        tv.setText(setTextSize(content, 0xffffffff, 25, content.length() - 2));
    }

    /**
     * 设置金额字体大小
     *
     * @param content
     */
    public SpannableString setTextSize(String content, int color, int size, int start) {
        ColorStateList colors = ColorStateList.valueOf(color);
        SpannableString ss = new SpannableString(content);
        ss.setSpan(new TextAppearanceSpan(null, 0, SizeUtils.dp2px(mContext, size), colors, null), start, ss.length(),
                Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
        return ss;
    }
}
